package com.student_system.system.controller;

import com.student_system.common.Result;
import com.student_system.dto.RoleMenuAssignDTO;
import com.student_system.system.service.ISysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljy
 * @since 2025-05-14
 */
@RestController
@RequestMapping("/sysRoleMenu")
public class SysRoleMenuController {

    @Autowired
    ISysRoleMenuService sysRoleMenuService;
    /**
     * 根据角色ID获取菜单ID列表
     * @param roleId
     * @return
     */
    @GetMapping("/getByRoleId")
    public Result.ResultData<List<Integer>> getByRoleId(@RequestParam Long roleId) {
        List<Integer> menuList = sysRoleMenuService.getMenuIdsByRoleId(roleId);
        return Result.success(menuList);
    }

    /**
     * 角色分配菜单并保存信息
     * @param dto
     * @return
     */
    @PostMapping("/assignMenus")
    public Result.ResultData<String> assignMenus(@RequestBody RoleMenuAssignDTO dto) { // 改为@RequestBody
        sysRoleMenuService.assignMenusToRole(dto.getRoleId(), dto.getMenuIds());
        return Result.success("分配菜单成功");
    }
}
